import {uploadOverdueCertificate,remissionCause} from '@/api/finance'
export default {
    data() {
        return {
            remissionTypeList: [],
            remissionAllList: [],
            remissionCauseList: [],
        }
    },
    methods: {
        // 提醒上传凭证
        async remindUpload(data) {
            const formData = new FormData()
            formData.append('file', data.file)
            formData.append('loanRecordId', this.routesQuery.orderId)
            const res = await uploadOverdueCertificate( formData)
            if (res.code === 1 && res.data) {
                // 清除上一次记录
                if (this.remindForm.certificate) this.$set(this.remindForm, 'certificate', null)
                this.$nextTick(() => {
                    this.$set(this.remindForm, 'certificate', res.data)
                })
            }
        },
        // 催收上传凭证
        async collectionUpload(data) {
            const formData = new FormData()
            formData.append('file', data.file)
            formData.append('loanRecordId', this.routesQuery.orderId)
            const res = await uploadOverdueCertificate(formData)
            if (res.code === 1 && res.data) {
                // 清除上一次记录
                if (this.collectionForm.certificate) this.$set(this.collectionForm, 'certificate', null)
                this.$nextTick(() => {
                    this.$set(this.collectionForm, 'certificate', res.data)
                })
            }
        },
        // 催收获取减免类型
        async getRemissionCause() {
            let permiss = []
            for (const key in this.permiss) {
                permiss.push(this.permiss[key])
            }
            if (permiss.indexOf('/remission/remissionCause')) {
                const res = await remissionCause()
                if (res.code === 1) {
                    this.remissionAllList = [...res.data]
                    this.remissionTypeList = [...res.data].filter(i => i.code === 0)
                }
            }
        },
        // 催收减免下拉
        collectionChangeType(key) {
            const selectType = this.remissionAllList.filter(i => i.key === key)
            const list = this.remissionAllList.filter(i => {
                return (i.type === selectType[0].type) && i.code !== 0
            })
            this.remissionCauseList = list
            if (selectType[0].isRemark && selectType[0].isRemark === 1) {
                // 类型其他 必填备注 去除原因校验
                this.collectionForm.remissionRequiredRemark = 1
            } else {
                this.collectionForm.remissionRequiredRemark = 0
            }
            if (this.collectionForm.cause2) this.collectionForm.cause2 = null
        },
        // 提醒减免下拉
        remindChangeType(key) {
            const selectType = this.remissionAllList.filter(i => i.key === key)
            const list = this.remissionAllList.filter(i => {
                return (i.type === selectType[0].type) && i.code !== 0
            })
            this.remissionCauseList = list
            if (selectType[0].isRemark && selectType[0].isRemark === 1) {
                // 类型其他 必填备注 去除原因校验
                this.remindForm.remissionRequiredRemark = 1
            } else {
                this.remindForm.remissionRequiredRemark = 0
            }
            if (this.remindForm.cause2) this.remindForm.cause2 = null
        },
    }
}
